package com.ionehe.model;

import cn.hutool.json.JSONUtil;
import com.ionehe.model.api.Message;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;
@Data
public class BrokerMessage implements Serializable {
     
    private static final long serialVersionUID = 7447792462810110841L;
 
    private String messageId;
 
    private Message message;

    private String messageJ;

    private Integer tryCount = 0;
 
    private String status;
 
    private Date nextRetry;
 
    private Date createTime;
 
    private Date updateTime;

    public void setMessage(Message message) {
        this.message = message;
        this.messageJ = JSONUtil.toJsonStr(message);
    }

    public Message getMessage() {
        if (message == null && messageJ != null) {
            return JSONUtil.toBean(messageJ, Message.class);
        }
        return message;
    }

    public void setMessageId(String messageId) {
        this.messageId = messageId == null ? null : messageId.trim();
    }

}